<?php

class Application_Model_CartProduct {
	
	protected $id_cart;
	protected $id_product;
	
	public function __construct(array $options = null){
		if (is_array($options)) {
			$this->setOptions($options);
		}
	}
	
	public function __set($name, $value){
		$method = 'set' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid cart/product property');
		}
		$this->$method($value);
	}
	
	public function __get($name){
		$method = 'get' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid cart/product property');
		}
		return $this->$method();
	}
	
	public function setOptions(array $options){
		$methods = get_class_methods($this);
		foreach ($options as $key => $value) {
			$method = 'set' . ucfirst($key);
			if (in_array($method, $methods)) {
				$this->$method($value);
			}
		}
		return $this;
	}
	
	public function setId_cart($id_cart){
		$this->id_cart = (int) $id;
		return $this;
	}
	
	public function getId_cart(){
		return $this->id_cart;
	}
	
	public function setId_product($id_product){
		$this->id_product = (int) $id_product;
		return $this;
	}
	
	public function getId_product(){
		return $this->id_product;
	}
}

